/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * Author     : 王海斌
 * E-mail     : wanghaibin@qiyi.com
 * Version    :
 * Date       : Thu 03 Dec 2020 10:43:26 AM CST
 * Destription:  测试字符串格式化相关内容
 */

#include <stdio.h>

/**
 * 测试将数字按指定宽度进行格式化，不够的补0
 */
void test_format_number() {
    int number = 10;
    char buf[64]={0};
    sprintf(buf, "%05d", number);
    printf("number=%d, str=%s\n", number, buf);
    number = 1234;
    sprintf(buf, "%05d", number);
    printf("number=%d, str=%s\n", number, buf);
    number = 12345;
    sprintf(buf, "%05d", number);
    printf("number=%d, str=%s\n", number, buf);
    number = 123456; // 当长度超过指定的05时则使用原始字符串
    sprintf(buf, "%05d", number);
    printf("number=%d, str=%s\n", number, buf);

    const char * path="/a/b/c/d/";
    size_t file_seq_ = 32;
    char tmpbuf[256]={0};
    snprintf(tmpbuf, 256, "%s%05zd", path, file_seq_);
    printf("new path=%s\n", tmpbuf);
}

int main(int argc, char *argv[])
{
    (void) argc;
    (void) argv;

    test_format_number();
    return 0;
}
